package com.crm.controller.system;

import com.crm.aonnation.Log;
import com.crm.dto.DeptDto;
import com.crm.pojo.Dept;
import com.crm.pojo.Menu;
import com.crm.result.ResponseResult;
import com.crm.result.Result;
import com.crm.service.system.DeptService;
import com.crm.vo.TreeselectVO;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName DeptController
 * @Description
 * @Author 19632
 * @Date 2024/10/29 11:37
 * @Version
 **/
@RestController
@Slf4j
public class DeptController {

    @Autowired
    private DeptService deptService;


    @GetMapping("/system/dept/list")

    public ResponseResult list(String status, String deptName) {
        List<Dept> deptList = deptService.list(status, deptName);
        return ResponseResult.success().put("data", deptList);
    }

    @PostMapping("/system/dept")
   // @Log
    public ResponseResult add(@RequestBody Dept dept) {
        deptService.add(dept);
        return ResponseResult.success();
    }

    @GetMapping("/system/dept/{deptId}")
   // @Log
    public Result<Dept> getById(@PathVariable Integer deptId) {
        Dept dept = deptService.getByDeptId(deptId);
        return Result.success(dept);
    }

    @GetMapping("/system/dept/list/exclude/{deptId}")
   // @Log
    public ResponseResult getByDeptId(@PathVariable Integer deptId) {
        List<Dept> deptList = deptService.getByDeptIdlist(deptId);
        return ResponseResult.success().put("data", deptList);
    }

    @PutMapping("/system/dept")
   // @Log
    public ResponseResult update(@RequestBody Dept dept) {
        deptService.update(dept);
        return ResponseResult.success();
    }
    @DeleteMapping("/system/dept/{deptId}")

    public ResponseResult delete(@PathVariable Integer deptId) {
        deptService.delete(deptId);
        return ResponseResult.success();
    }

    @GetMapping("/system/dept/treeselect")
    //@Log
    public ResponseResult getTree() {
        List<TreeselectVO> deptList = deptService.getTree();
        return ResponseResult.success(deptList);
    }
}
